From 4da23c0c03180cbd51e77a858c6f0230e489118c Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Fri, 13 Nov 2009 15:31:45 +0000 Subject: [PATCH] x86: Change the interface physdev_map_pirq to support new dom0. It also keeps compatibility with old dom0. Signed-off-by: Xiantao Zhang --- xen/arch/x86/irq.c | 18 +++++++++++++++++- xen/arch/x86/physdev.c | 30 +++++++++++++++++------------- xen/include/asm-x86/irq.h | 2 ++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/xen/arch/x86/irq.c b/xen/arch/x86/irq.c index 222b9c62ea..da77276634 100644 --- a/xen/arch/x86/irq.c +++ b/xen/arch/x86/irq.c @@ -64,6 +64,11 @@ static struct timer irq_ratelimit_timer; static unsigned int __read_mostly irq_ratelimit_threshold = 10000; integer_param("irq_ratelimit", irq_ratelimit_threshold); +int check_irq_status(int irq) +{ + return irq_status[irq] != IRQ_UNUSED ? 1 : 0; +} + /* Must be called when irq disabled */ void lock_vector_lock(void) { @@ -716,6 +721,9 @@ int setup_irq(unsigned int irq, struct irqaction *new) desc->status &= ~IRQ_DISABLED; desc->handler->startup(irq); + if ( !check_irq_status(irq) ) + irq_status[irq] = IRQ_USED; + spin_unlock_irqrestore(&desc->lock,flags); return 0; @@ -1404,6 +1412,8 @@ int map_domain_pirq( ASSERT(spin_is_locked(&pcidevs_lock)); ASSERT(spin_is_locked(&d->event_lock)); + + desc = irq_to_desc(irq); if ( !IS_PRIV(current->domain) && !(IS_PRIV_FOR(current->domain, d) && @@ -1417,6 +1427,13 @@ int map_domain_pirq( return -EINVAL; } + if ( desc->action ) + { + dprintk(XENLOG_G_WARNING, "Attempt to map in-use IRQ by Xen," + " irq:%d!\n", irq); + return 0; + } + old_irq = domain_pirq_to_irq(d, pirq); old_pirq = domain_irq_to_pirq(d, irq); @@ -1436,7 +1453,6 @@ int map_domain_pirq( return ret; } - desc = irq_to_desc(irq); if ( type == MAP_PIRQ_TYPE_MSI ) { diff --git a/xen/arch/x86/physdev.c b/xen/arch/x86/physdev.c index 2d65fa4df4..3f6cc82f4b 100644 --- a/xen/arch/x86/physdev.c +++ b/xen/arch/x86/physdev.c @@ -30,7 +30,7 @@ ioapic_guest_write( static int physdev_map_pirq(struct physdev_map_pirq *map) { struct domain *d; - int pirq, irq, ret = 0; + int pirq = 0, irq, ret = 0; struct msi_info _msi; void *map_data = NULL; @@ -55,23 +55,28 @@ static int physdev_map_pirq(struct physdev_map_pirq *map) switch ( map->type ) { case MAP_PIRQ_TYPE_GSI: - if ( map->index < 0 || map->index >= nr_irqs_gsi ) + { + int gsi, triggering, polarity; + + gsi = map->index & 0xffff; + triggering = !!(map->index & (1 << 16)); + polarity = !!(map->index & (1 << 24)); + irq = pirq = map->pirq; + + if ( gsi < 0 || gsi >= nr_irqs_gsi ) { - dprintk(XENLOG_G_ERR, "dom%d: map invalid irq %d\n", - d->domain_id, map->index); + dprintk(XENLOG_G_ERR, "dom%d: map invalid gsi %d\n", + d->domain_id, gsi); ret = -EINVAL; goto free_domain; } - irq = domain_pirq_to_irq(current->domain, map->index); - if ( !irq ) - { - dprintk(XENLOG_G_ERR, "dom%d: map pirq with incorrect irq!\n", - d->domain_id); - ret = -EINVAL; - goto free_domain; + if ( !check_irq_status(irq) ) { + mp_register_gsi(gsi, triggering, polarity); + printk("Register gsi:%d for dom:%d, irq:%d\n", gsi, + d->domain_id, irq); } break; - + } case MAP_PIRQ_TYPE_MSI: irq = map->index; if ( irq == -1 ) @@ -103,7 +108,6 @@ static int physdev_map_pirq(struct physdev_map_pirq *map) spin_lock(&pcidevs_lock); /* Verify or get pirq. */ spin_lock(&d->event_lock); - pirq = domain_irq_to_pirq(d, irq); if ( map->pirq < 0 ) { if ( pirq ) diff --git a/xen/include/asm-x86/irq.h b/xen/include/asm-x86/irq.h index c10aafb59c..d080beef23 100644 --- a/xen/include/asm-x86/irq.h +++ b/xen/include/asm-x86/irq.h @@ -143,6 +143,8 @@ void move_masked_irq(int irq); void irq_set_affinity(int irq, cpumask_t mask); +int check_irq_status(int irq); + #define domain_pirq_to_irq(d, pirq) ((d)->arch.pirq_irq[pirq]) #define domain_irq_to_pirq(d, irq) ((d)->arch.irq_pirq[irq]) -- 2.30.2